﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace WebReader
{
    public static class XmlHelper
    {
        static string filePath;
        static FileStream fsRead;
        static FileStream fsWrite;       
        static string fileName;

        static XmlSerializer xs = new XmlSerializer(typeof(Articles));



        public static void Serial(string _filePath, string _fileName, ref Articles _articles)
        {
            filePath = _filePath;
            fileName = _fileName;
           
            try
            {
                fsWrite = new FileStream(filePath + fileName, FileMode.Create, FileAccess.ReadWrite);
                xs.Serialize(fsWrite, _articles);
                fsWrite.Flush();
                fsWrite.Close();
            }
            catch
            {
            }

        }

        public static void DeSerial(string _filePath, string _fileName, ref Articles _articles)
        {
            filePath = _filePath;
            fileName = _fileName;
            if (File.Exists(filePath + fileName))
            {
                try
                {
                    fsRead = new FileStream(filePath + fileName, FileMode.Open, FileAccess.Read);
                    _articles = (Articles)xs.Deserialize(fsRead);
                    fsRead.Flush();
                    fsRead.Close();
                }
                catch
                {
                }
            }
        }

    }
}
